// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

// 类型定义
export interface UserVO {
  userId: number;
  userName: string;
  pid: string;
  telephone: string;
  address: string;
  adminAccount?: string;
  isAdmin: boolean;
  createTime: string;
  updateTime: string;
}

export interface CustomerCreateDTO {
  userName: string;
  pid: string;
  telephone: string;
  address: string;
  password?: string;
}

export interface CustomerUpdateDTO {
  userId: number;
  userName: string;
  telephone: string;
  address: string;
}

export interface CustomerQueryDTO {
  page: number;
  pageSize: number;
  userId?: number;
  userName?: string;
  pid?: string;
  telephone?: string;
  address?: string;
  isAdmin?: boolean;
}

export interface PageResult<T> {
  total: number;
  records: T[];
}

export interface Result<T> {
  code: number;
  msg: string | null;
  data: T;
}

/**
 * 创建客户
 */
export async function createCustomer(customerCreateDTO: CustomerCreateDTO): Promise<Result<null>> {
  return request<Result<null>>('/api/admin/customers', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: customerCreateDTO,
  });
}

/**
 * 分页查询客户列表
 */
export async function pageCustomers(queryDTO: CustomerQueryDTO): Promise<Result<PageResult<UserVO>>> {
  return request<Result<PageResult<UserVO>>>('/api/admin/customers/page', {
    method: 'GET',
    params: queryDTO,
  });
}

/**
 * 根据用户ID查询客户信息
 */
export async function getCustomerById(userId: number): Promise<Result<UserVO>> {
  return request<Result<UserVO>>(`/api/admin/customers/${userId}`, {
    method: 'GET',
  });
}

/**
 * 更新客户信息
 */
export async function updateCustomer(customerUpdateDTO: CustomerUpdateDTO): Promise<Result<null>> {
  return request<Result<null>>('/api/admin/customers', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: customerUpdateDTO,
  });
}

/**
 * 删除客户
 */
export async function deleteCustomer(userId: number): Promise<Result<null>> {
  return request<Result<null>>(`/api/admin/customers/${userId}`, {
    method: 'DELETE',
  });
} 